﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyD
{
    class FocusColorHandler
    {
        public void RichTextBoxToPanel(object objIn, object objOut, Color defaultColor, Color highlightColor)
        {
            try
            {
                RichTextBox _in = (RichTextBox)objIn;
                Panel _out = (Panel)objOut;

                _in.GotFocus += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = highlightColor;
                    }
                );

                _in.LostFocus += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = defaultColor;
                    }
                );
            }
            catch { }
        }

        public void TextBoxToPanel(object objIn, object objOut, Color defaultColor, Color highlightColor)
        {
            try
            {
                TextBox _in = (TextBox)objIn;
                Panel _out = (Panel)objOut;

                _in.GotFocus += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = highlightColor;
                    }
                );

                _in.LostFocus += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = defaultColor;
                    }
                );
            }
            catch { }
        }

        public void ListBoxToPanel(object objIn, object objOut, Color defaultColor, Color highlightColor)
        {
            try
            {
                ListBox _in = (ListBox)objIn;
                Panel _out = (Panel)objOut;

                _in.GotFocus += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = highlightColor;
                    }
                );

                _in.LostFocus += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = defaultColor;
                    }
                );
            }
            catch { }
        }

        public void PanelToPanel(object objIn, object objOut, Color defaultColor, Color highlightColor)
        {
            try
            {
                Panel _in = (Panel)objIn;
                Panel _out = (Panel)objOut;

                _in.MouseEnter += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = highlightColor;
                    }
                );

                _in.MouseLeave += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = defaultColor;
                    }
                );
            }
            catch { }
        }

        public void LabelToPanel(object objIn, object objOut, Color defaultColor, Color highlightColor)
        {
            try
            {
                Label _in = (Label)objIn;
                Panel _out = (Panel)objOut;

                _in.MouseEnter += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = highlightColor;
                    }
                );

                _in.MouseLeave += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = defaultColor;
                    }
                );
            }
            catch { }
        }

        public void ButtonToPanel(object objIn, object objOut, Color defaultColor, Color highlightColor)
        {
            try
            {
                Button _in = (Button)objIn;
                Panel _out = (Panel)objOut;

                _in.MouseEnter += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = highlightColor;
                    }
                );

                _in.MouseLeave += new EventHandler(
                    delegate(Object o, EventArgs a)
                    {
                        _out.BackColor = defaultColor;
                    }
                );
            }
            catch { }
        }
    }
}
